package services.AZ10;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import vo.system.Az10;
import com.PublicSystem;
import com.util.Util;
/**
 * 制卡批次相关操作Service
 * @author duy
 * 
 */
public class AZ10Services {
	PublicSystem sys = PublicSystem.getInstance();
	/**
	 * 查询制卡信息
	 * @author duy
	 * @param obj
	 * @param parms
	 * @throws Exception
	 */
	public HashMap getAZ10(Object[] obj, HashMap parms) throws Exception {
    	String sql = "select aaz001,to_char(aaz707,'YYYY-MM-DD') aaz707,to_char(aaz708,'YYYY-MM-DD') aaz708,(case when aaz719 = '1' then '是' " +
    			"when aaz719 = '2' then '否' end) as aaz719,aae300,to_char(aaz402,'YYYY-MM-DD') " +
    			"aaz402,aaz705,to_char(aaz706,'YYYY-MM-DD') aaz706 from v_az10 t where " +
    			"('"+obj[0] + "' is null or AAZ402 >= TO_DATE(?,'YYYY-MM-DD')) and " +
    			"('"+obj[1] + "' is null or AAZ402 <= TO_DATE(?,'YYYY-MM-DD')) and " +
    			"('"+obj[2] + "' is null or AAZ001 like '%'||?||'%') and " +
    			"('"+obj[3] + "' is null or AAE300 like '%'||?||'%')";
    	HashMap map = sys.getGrid(sql, obj, parms, false);
    	return map;
	} 
	/**
	 * 新增制卡批次人员信息，利用存储过程获取
	 * @author duy
	 * @param obj
	 * @throws Exception
	 */
	public String insertAZ10(HashMap obj ) throws Exception {
		Az10 vo = new Az10();
		vo = (Az10)Util.MapToVo(vo, obj);
		String ss = sys.callDBFuncProce("ic_az10.set_az10", "function", obj);
		String[] str = ss.split("&");
		if("0".equals(str[0]) || null == str[0]) {
        	return "保存成功!";
        } else {
        	return "保存失败:原因为" + str[0];
        }
	} 
	/**
	 * 根据id获取个人基础信息
	 * @author duy
	 * @param id
	 * @throws Exception
	 */
	public HashMap getAZ10Data(String id) throws Exception {
		String sql1 = "select * from az10 where aaz001 =? ";
		List msg = sys.query(sql1, new Object[] {id} , true);
		HashMap map = new HashMap();
		if(msg.size() > 0) {		
			String sql2 = "select aaz001,aaz707,aaz708,(case when aaz719 = '1' then '是' " +
                    "when aaz719 = '2' then '否' end) as aaz719," +
                    "aae300,aaz402 from az10  where aaz706 is null and aaz001 like '%'||?||'%'";
          List data = sys.query(sql2, new Object[] {id} , true);
          if(data.size() > 0) {
        	  map = (HashMap)data.get(0);
        	  map.put("msg", "0");
        	  return map;        	 
          }  else {
        	  map.put("msg", "1");
        	  return map;
          }          
		} else {					
			map.put("msg", "2");
			return map;
		}    	
    		
	} 	
	/**
	 * 终止批次人员信息，利用存储过程获取
	 * @author duy
	 * @param obj
	 * @throws Exception
	 */
	public String endAZ10(HashMap obj ) throws Exception {
		Az10 vo = new Az10();
		vo = (Az10)Util.MapToVo(vo, obj);
		String ss = sys.callDBFuncProce("ic_az10.set_zkpc_zz", "function", obj);
		String[] str = ss.split("&");
		if("0".equals(str[0]) || null == str[0]) {
        	return "批次终止成功!";
        } else {
        	return "批次终止失败:原因为" + str[0];
        }
	} 
}